/**
 * XK Global.js
 * @author charlie高  on 20180803
 */
(function( global, factory ) {
    if ( typeof module === "object" && typeof module.exports === "object" ) {
        module.exports = global.document ?
            factory( global, true ) :
            function( w ) {
                if ( !w.document ) {
                    throw new Error( "jQuery requires a window with a document" );
                }
                return factory( w );
            };
    } else {
        factory( global );
    }
}(typeof window !== "undefined" ? window : this, function( window, noGlobal ) {

    var objPtt = Object.prototype,
        obj2Str = objPtt.toString,
        hasOwn = objPtt.hasOwnProperty,
        arrPtt = Array.prototype,
        support = {},
        class2type = {},
        ids = [],
        JGlobal = {};

    var indexOf = ids.indexOf;

    JGlobal.fn = JGlobal.prototype = { };

       //扩展extends
    JGlobal.ex = JGlobal.fn.ex = function() {
        var src, copyIsArray, copy, name, options, clone,
            target = arguments[ 0 ] || {},//第一个参数
            i = 1,
            length = arguments.length,
            deep = false;

        if ( typeof target === "boolean" ) {
            deep = target;
            target = arguments[ i ] || {};
            i++;
        }

        if ( typeof target !== "object" && !JGlobal.isFunction( target ) ) {
            target = {};
        }

        if ( i === length ) {
            target = this;
            i--;
        }

        for ( ; i < length; i++ ) {
            if ( ( options = arguments[ i ] ) != null ) {
                for ( name in options ) {
                    src = target[ name ];
                    copy = options[ name ];

                    if ( target === copy ) {
                        continue;
                    }

                    // Recurse if we're merging plain objects or arrays
                    if ( deep && copy && ( JGlobal.isPlainObject( copy ) ||
                        ( copyIsArray = JGlobal.isArray( copy ) ) ) ) {

                        if ( copyIsArray ) {
                            copyIsArray = false;
                            clone = src && JGlobal.isArray( src ) ? src : [];

                        } else {
                            clone = src && JGlobal.isPlainObject( src ) ? src : {};
                        }
                        target[ name ] = JGlobal.ex( deep, clone, copy );

                        // Don't bring in undefined values
                    } else if ( copy !== undefined ) {
                        target[ name ] = copy;
                    }
                }
            }
        }
        return target;
    };


    JGlobal.ex({
        error: function( msg ) {
            throw new Error( msg );
        },
        noop: function() {},
        hasProp: function(obj, prop) {
            return hasOwn.call(obj, prop);
        },
        getOwn: function(obj, prop) {
            return JGlobal.hasProp(obj, prop) && obj[prop];
        },
        isBool: function(checkIt){
            return obj2Str.call(checkIt) === "[object Boolean]";
        },
        isFunction: function( obj ) {
            return JGlobal.type( obj ) === "function";
        },
        isArray: Array.isArray || function( obj ) {
            return JGlobal.type( obj ) === "array";
        },
        isWindow: function( obj ) {
            return obj != null && obj == obj.window;
        },
        isNumeric: function( obj ) {
            var realStringObj = obj && obj.toString();
            return !JGlobal.isArray( obj ) && ( realStringObj - parseFloat( realStringObj ) + 1 ) >= 0;
        },
        isEmptyObject: function( obj ) {
            var name;
            for ( name in obj ) {
                return false;
            }
            return true;
        },
        isPlainObject: function( obj ) {
            var key;
            if ( !obj || JGlobal.type( obj ) !== "object" || obj.nodeType || JGlobal.isWindow( obj ) ) {
                return false;
            }

            try {
                if ( obj.constructor &&
                    !hasOwn.call( obj, "constructor" ) &&
                    !hasOwn.call( obj.constructor.prototype, "isPrototypeOf" ) ) {
                    return false;
                }
            } catch ( e ) {
                // IE8,9 Will throw exceptions on certain host objects #9897
                return false;
            }

            // Support: IE<9
            // Handle iteration over inherited properties before own properties.
            if ( !support.ownFirst ) {
                for ( key in obj ) {
                    return hasOwn.call( obj, key );
                }
            }

            // Own properties are enumerated firstly, so to speed up,
            // if last one is own, then all properties are own.
            for ( key in obj ) {}

            return key === undefined || hasOwn.call( obj, key );
        },

        type: function( obj ) {
            if ( obj == null ) {
                return obj + "";
            }
            return typeof obj === "object" || typeof obj === "function" ?
                class2type[ toString.call( obj ) ] || "object" :
                typeof obj;
        },
        inArray: function( elem, arr, i ) {
            var len;

            if ( arr ) {
                if ( indexOf ) {
                    return indexOf.call( arr, elem, i );
                }

                len = arr.length;
                i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0;

                for ( ; i < len; i++ ) {

                    // Skip accessing in sparse arrays
                    if ( i in arr && arr[ i ] === elem ) {
                        return i;
                    }
                }
            }

            return -1;
        },
        support: support
    } );
    if ( !noGlobal ) {
        window.JGlobal = window.$$ = JGlobal;
    }
    return JGlobal;
}));